﻿using Nemerle.Text;
using Nemerle.Utility;

using System;
using System.Collections.Generic;
using System.Linq;

namespace Nemerle.Data
{
  public module Tuples
  {
    /// <summary>
    /// Extract the first component of a pair.
    /// </summary>
    public First[T, U](this pair : T * U) : T
    {
      pair[0]
    }
    
    /// <summary>
    /// Extract the first component of a tuple.
    /// </summary>
    public First[T, U, V](this pair : T * U * V) : T
    {
      pair[0]
    }
    
    /// <summary>
    /// Extract the second component of a pair.
    /// </summary>
    public Second[T, U](this pair : T * U) : U
    {
      pair[1]
    }
    
    /// <summary>
    /// Extract the second component of a tuple.
    /// </summary>
    public Second[T, U, V](this pair : T * U * V) : U
    {
      pair[1]
    }
    
    /// <summary>
    /// Extract the third component of a tuple.
    /// </summary>
    public Third[T, U, V](this pair : T * U * V) : V
    {
      pair[2]
    }
    
    public Swap[T, U](this pair : T * U) : U * T
    {
      def (f, s) = pair;
      (s, f)
    }
    
    public Shift[T, U, V](this triple : T * U * V) : U * V * T
    {
      def (f, s, t) = triple;
      (s, t, f)
    }
    
    public ShiftRight[T, U, V](this triple : T * U * V) : V * T * U
    {
      def (f, s, t) = triple;
      (t, f, s)
    }
  }
}
